package com.mytaobao.repositories;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import com.mytaobao.pojo.Customer;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.criteria.CriteriaBuilder;
import java.util.List;

//public interface CustomerRepository extends CrudRepository<Customer,Integer> {
public interface CustomerRepository extends PagingAndSortingRepository<Customer, Integer> {
    @Query("from Customer where name=?1")
    List<Customer> findCustomerByName(String name);

    @Query("from Customer where name=:n")
    List<Customer> findCustomerByName2(@Param("n") String name);

    @Transactional
    @Modifying
    @Query("update Customer c set c.name=:n where c.id=:id")
    Integer myUpdate(@Param("n") String name, @Param("id") Integer id);

    @Transactional
    @Modifying
    @Query("delete from Customer c where c.id=:id")
    Integer myDelete(@Param("id") Integer id);

    @Query(value = "select * from tb_user where id=:id", nativeQuery = true)
    List<Customer> nativeQuery(@Param("id") Integer id);
}
